<?php

//创建server 监听 9501端口
$server = new swoole_server('127.0.0.1',9501);
//设置运行时的参数
$server->set([
	'worker_num'=>4,
	'max_requert'=>1000,
]);

/*
	监听连接进入事件
	$fd 客户端连接的唯一标示
	$reactor_id	线程id
*/
$server->on('connect',function($server,$fd,$reactor_id){
	echo "Clinet:{$reactor_id} - {$fd}-connect \n";
});

/*
	监听数据接收事件
	$reactor_id = $from_id
*/

$server->on('receive',function($server,$fd,$reactor_id,$data){
	$server->send($fd,"Server:{$reactor_id} - {$fd} ".$data." \n");
});

//
$server->on('close',function($server,$fd){
	echo "Clinet: Close\n";
});

$server->start();